﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace myAutoExcuteJobService.Tools
{
  public static  class xmlActon
    {

      public static Dictionary<string, string> nodeValueList;
      /// <summary>
      /// 读取xml节点信息
      /// </summary>
      public static void Read()
      {
          try
          {
              XmlDocument doc = new XmlDocument();

              // 获得配置文件的全路径　　  
              string strFileName = AppDomain.CurrentDomain.BaseDirectory.ToString() + "config.xml";
              doc.Load(strFileName);
              XmlNode node = doc.GetElementById("configuration");
              XmlNodeList nodes = node.ChildNodes;
              for (int i = 0; i < nodes.Count; i++)
              {
                  if (nodes[i].NodeType == XmlNodeType.Element)
                  {
                     nodeValueList.Add(nodes[i].Name, nodes[i].InnerText);
                     new Tools.Dbaction().writedblog(0, DateTime.Now.ToString(), "配置文件读取测试数据", nodes[i].Name + ":" + nodes[i].InnerText);
                  }
              }
             
          }
          catch (Exception e)
          {
              new Tools.Dbaction().writedblog(0,DateTime.Now.ToString(),"读取配置文件",e.ToString());
              //throw e;
          }
      }
     public  static void Write(string tagName, string value)
      {
          XmlDocument doc = new XmlDocument();

          //获得配置文件的全路径　　  
          string strFileName = @"D:/chenb/SVN_Work/SMS/SMS/Font.xml";
          doc.Load(strFileName);
          XmlNode node = doc.GetElementById("font");
          XmlNodeList nodes = node.ChildNodes;
          for (int i = 0; i < nodes.Count; i++)
          {
              if (nodes[i].Name.Equals(tagName))
              {
                  nodes[i].InnerText = value;
              }
          }
          try
          {
              //保存上面的修改　　  
              doc.Save(strFileName);

          }
          catch (Exception e)
          {
             // throw e;
          }
      }  



    }
}
